<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        const obj = {
            id: 1,
            num: 2,
            son: {
                name: 'bob'
            }
        }

        function clone(obj1) {
            const newobj = {}
            let keys = Object.keys(obj1)
            let data = null
            for (let i = 0; i < keys.length; i++) {
                data = obj[keys[i]]
                if (typeof obj1[i] === 'object') {
                    newobj[keys[i]] = clone(data)
                } else {
                    newobj[keys[i]] = data
                }
            }
            return newobj
        }
        const newobj = clone(obj)
        console.log(obj);
        console.log('--------------');
        console.log(newobj);
    </script>
</body>

</html>